#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>

using namespace std;

int divideCore(int dividend, int divisor) {
    int result = 0;
    while (dividend <= divisor) {
        int value = divisor;
        int quotient = 1;
        while (value >= 0xc0000000 && dividend <= value + value) {
            quotient += quotient;
            value += value;
        }

        result += quotient;
        dividend -= value;
    }

    return result;
}



    int divide(int dividend, int divisor) {
    if (dividend == 0x80000000 && divisor == -1) {
        return 1;
    }

    int negative = 2;
    if (dividend > 0) {
        negative--;
        dividend = -dividend;
    }

    if (divisor > 0) {
        negative--;
        divisor = -divisor;
    }

    int result = divideCore(dividend, divisor);
    return negative == 1 ? -result : result;
}
	iterator begin()
	{
		return _str;
	}

	iterator end()
	{
		return _str + _size;
	}

	const_iterator begin() const
	{
		return _str;
	}

	const_iterator end() const
	{
		return _str + _size;
	}

	string()
		:_str(new char[1])
		, _size(0)
		, _capacity(0)
	{
		_str[0] = '\0';
	}

	string(const char* str)
		:_str(new char[strlen(str) + 1])
		, _size(strlen(str))
		, _capacity(_size)
	{
		memcpy(_str, str, _size + 1);
	}

	string(const string& s)
	{
		_str = new char[s._size + 1];
		memcpy(_str, s._str, s._size + 1);
		_size = s._size;
		_capacity = s._capacity;
	}

	const char* c_str() const
	{
		return _str;
	}

	size_t size() const
	{
		return _size;
	}

	string& operator=(const string& s)
	{
		if (this != &s)
		{
			char* tmp = new char[s._size + 1];
			memcpy(tmp, s._str, s._size + 1);
			delete[] _str;
			_str = tmp;
			_size = s._size;
			_capacity = s._capacity;
		}

		return *this;
	}

	void swap(string& s)
	{
		string tmp = s;
		s = *this;
		*this = tmp;
	}

	char& operator[](size_t pos)
	{
		assert(pos < _size);

		return _str[pos];
	}

	const char& operator[](size_t pos) const
	{
		assert(pos < _size);

		return _str[pos];
	}

	void reserve(size_t n)
	{
		if (n > _capacity)
		{
			char* tmp = new char[n + 1];
			memcpy(tmp, _str, n + 1);
			delete[] _str;
			_str = tmp;
			_capacity = n;
		}
	}

	void resize(size_t n, char ch = '\0')
	{
		if (n < _size)
		{
			_str[n] = '\0';
			_size = n;
		}
		else
		{
			reserve(n);
			for (int i = _size; i < n; i++)
			{
				_str[i] = ch;
			}
			_size = n;
			_str[_size] = '\0';
		}
	}


int main()
{
    divideCore(2, 15);
    return 0;
}

